﻿@model RBAC.Web.Models.FunctionModel
@using RBAC.Web.CustomHelpers
@using RBAC.Web.Mapper
@using RBAC.Web.Utilities
@{
    ViewBag.Title = "Add Function";
    Layout = "~/Views/Shared/_Layout.cshtml";

    string returnUrl = "";
    string DomainName = "";
    if (TempData["DomainLookupField"] == null || String.IsNullOrEmpty(TempData["DomainLookupField"].ToString()))
    {
        returnUrl = Url.Action("ListFunction", "Function");
    }
    else
    {
        DomainName = TempData["DomainLookupField"].ToString();
        returnUrl = Url.Action("EditDomain", "Domain", new { DomainName = DomainName });
    }  
																							 
}

@section Styles {
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/form.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet" type="text/css" />

    <link href="@Url.Content("~/Content/bootstrap/css/utility.css")" rel="stylesheet"    type = "text/css">

    <script type="text/javascript">
        $(function () {
            //How to setup Datepicker
            // SetDatePicker has 4 argurement
            // controlId -> id of control
            // maxdate -> maximun Date that can be selected 
            // mindate -> minimum Date that can be selected 
            // yearrange - > range of year
            // more information see http://api.jqueryui.com/datepicker/
            //ถ้าไม่มีกำหนด maxdate, mindate, yearrange
            SetDatePicker("FreeDate");			 

            //How to setup Lookup
            // SetLookupFor has 3 argurement
            // controlId -> id of control
            // getLookupId -> hidden control's id for getlookup link
            // popLookupId -> hidden control's id for poplookup link
            SetExternalLookupFor("Function_Domain", "Function_DomainGetExternalLookup", 
"Function_DomainPopExternalLookup", 'Function_Domain|Function_DomainLookupField');
			
            SetExternalLookupFor("Function_DomainLookup", "Function_DomainLookupGetExternalLookup", 
"Function_DomainLookupPopExternalLookup", 'Function_DomainLookup|Function_DomainLookupLookupField|DomainLookupId');
			
        });
    </script>
}


<h3 class="page-header">Function</h3>

@using (Html.BeginForm("AddFunction", "Function", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{


    //version 1.3 Bootstrap 7/4/2014
    <div class="panel panel-primary">
        <div class="panel-heading">FunctionModel </div>
        <div class="panel-body">


            @Html.Hidden("Parent_DomainDomainName", @DomainName)

            <div class="form-group row">



                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.FuncName)</label>
                    </div>

                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.FuncName, new { @class = "form-control" })

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.FuncName)
                    </div>
                </div>

                <input type="hidden" name="Mode" value="Add" />



                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.Description)</label>
                    </div>

                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.Description, new { @class = "form-control" })

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.Description)
                    </div>
                </div>

               
                @*chayawooth*********************@
                

                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.Domain)</label>
                    </div>

                    <div class="col-md-8">
                        @Html.ExternalLookup(model => model.DomainDomainName, "Function_Domain").For(model => model.Domain).Render(Utilities.CheckNullOrEmpty<string>(DomainName))


                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.DomainDomainName)
                    </div>
                </div>

                @*chayawooth*********************@  


                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.FunctionStatus)</label>
                    </div>
                    <div class="col-md-8">
                        @Html.RadioButtonForSelectList(model => model.FunctionStatus, FunctionStatusMapper.GetFunctionStatusSelectList())

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.FunctionStatus)
                    </div>
                </div>





                <div class="col-md-6">
                    <div class="col-md-4">
                        <label class="word-control-res">@Html.LabelFor(model => model.FunctionName)</label>
                    </div>
                    <div class="col-md-8">
                        @Html.DropDownListWithDefaultValueFor(model => model.FunctionName, FunctionNameMapper.GetFunctionNameSelectList())

                    </div>
                    <div class="col-md-offset-4 col-md-8">
                        @Html.ValidationMessageFor(model => model.FunctionName)
                    </div>
                </div>







            </div>

            <div class="col-md-6">
                <div class="btn-group">
                    <label>
                        <input type="submit" value="Add" class="btn btn-primary" /></label>
                    <label>
                        <input id="cancel" onclick="location.href='@returnUrl    '" type="button" value="Cancel" class="btn btn-primary" /></label>
                </div>
            </div>

        </div>
    </div>
}
